package servlet.admin;

import com.alibaba.fastjson.JSON;
import pojo.Result;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/deleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userIdStr = req.getParameter("userId");
        int userId = Integer.parseInt(userIdStr);
        Result result = null;
        if (userService.removeById(userId)) {
            result = Result.success();
        } else {
            result = Result.error("删除失败");
        }
        resp.setContentType("application/json;charset=UTF-8");
        resp.getWriter().write(JSON.toJSONString(result));
    }
}
